home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13359 < prev    next >
Encoding:
Text File  |  1996-08-05  |  6.8 KB  |  252 lines

  1. Path: news.itsnet.com!usenet
  2. From: Jonathan Ord <jord@itsnet.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: HELP PLEASE HELP
  5. Date: Sun, 24 Mar 1996 20:49:31 -0800
  6. Organization: Internet Technology Systems, Provo UT USA
  7. Message-ID: <315625DB.3F21@itsnet.com>
  8. NNTP-Posting-Host: ip211.itsnet.com
  9. Mime-Version: 1.0
  10. Content-Type: multipart/mixed; boundary="------------18637EF67123"
  11. X-Mailer: Mozilla 2.0 (Win95; I)
  12.  
  13. This is a multi-part message in MIME format.
  14.  
  15. --------------18637EF67123
  16. Content-Type: text/plain; charset=us-ascii
  17. Content-Transfer-Encoding: 7bit
  18.  
  19. I am just starting out and having some trouble.  I am trying to learn
  20. this out of a book.  I have started by trying to complete an assignment
  21. using linked lists and functions.  I continue to get errors and can't
  22. figure out how to delete a record from a specified record in the lists
  23. that I create.
  24.  
  25. This is the criteria for the excercise.
  26.  
  27. Your program must display the following menu:
  28. 1.      Add a stamp to the list
  29. 2.      Display all the stamps in your list
  30. 3.      Display the least expensive stamp in the list
  31. 4.      Display the most expensive stamp in the list
  32. 5.      Remove a particular stamp from the list
  33. 6.      Exit the program
  34.  
  35. After displaying the menu, ask the user to enter a choice, then perform
  36. the requested action and repeat this process until the user chooses to
  37. exit.
  38. Design an appropriate sturcture to capture 3 properties of stamp
  39. collection.  Store the stamps in a linked list. (using C++ new and
  40. delete operators to allocate and deallocate storage for the stamp
  41. structures.
  42. Be sure that all of the structures work whether the list is empty or
  43. not.  Redisplay the menu if a choice is not valid.
  44. For item 5, I have to devise a way for the user to indicate which stamp
  45. is to be deleted.  Two possibilities include asking the user for a
  46. description of the stam to delete or showing the user each stamp and
  47. asking him or her to say whether this is the one to delete.
  48.  
  49. Anyone that can help me please feel free to look at my program and make
  50. changes and comments and e-mail it back to me @jord@itsnet.com .
  51.  
  52. I would like to receive some feedback tonight if possible.  Thank you in
  53. advance for the help.
  54. --
  55.  
  56.  
  57. --
  58.  
  59. --------------18637EF67123
  60. Content-Type: text/plain; charset=us-ascii
  61. Content-Transfer-Encoding: 7bit
  62. Content-Disposition: inline; filename="Exam_2.cpp"
  63.  
  64. /*    Jonathan Ord
  65.     ISYS 440 Exam #2
  66.     Dr. Little
  67.     March 23, 1996
  68.     Description ==The program will let me keep track of rare stamps through the
  69.     use of the functions associated with the following menu:
  70.         1.  Add stamp to list
  71.         2.     Display all the stamps in the list
  72.         3.     Display the least expensive stamp in the list
  73.         4.  Display the most expensive stamp in the list
  74.         5.  Remove a particular stamp from the list
  75.         6.     Exit the program
  76. */
  77. //------------------------------------------------------------------------------
  78. //INCLUDES
  79.  
  80. #include <iostream.h>
  81. #include <string.h>
  82.  
  83. //------------------------------------------------------------------------------
  84. //VARIABLES
  85.  
  86. struct STAMP {
  87.     char    *name;
  88.     long    price;
  89.     int    mint_number;
  90.     STAMP    *next;
  91. };
  92.  
  93. const int MAX_STRING_LEN = 128;
  94.  
  95. //==============================================================================
  96. //FUNCTIONS
  97. //------------------------------------------------------------------------------
  98. //Enter stamp data function
  99.  
  100. void
  101. Enter_Stamp_Data(STAMP *stp)
  102. {
  103.     char    temp_string[MAX_STRING_LEN];
  104.  
  105.     cout    <<    "ENTER THE STAMP NAME: ";
  106.     cin.get(temp_string, MAX_STRING_LEN);
  107.     stp->name = new char [strlen(temp_string) + 1];
  108.     strcpy(stp->name, temp_string);
  109.     cout    << "ENTER THE STAMP'S PRICE IN PESETAS: ";
  110.     cin    >>    stp->price;
  111.     cout  << "ENTER THE STAMP'S MINT NUMBER: ";
  112.     cin    >>    stp->mint_number;
  113. }
  114.  
  115. //------------------------------------------------------------------------------
  116. //Append stamp to end of linked list or end of previous node function
  117.  
  118. void
  119. Append_Stamp_Node(STAMP * &first, STAMP *stp_ptr)
  120. {
  121.     if    (first == NULL)
  122.         first = stp_ptr;
  123.     else {
  124.         STAMP    *current = first;
  125.  
  126.         while (current->next != NULL)
  127.             current = current->next;
  128.         current->next = stp_ptr;
  129.         }
  130. }
  131.  
  132. //------------------------------------------------------------------------------
  133. //Display all of the stamps in the list function
  134.  
  135. void
  136. Display_Stamp_Data(STAMP * &head, STAMP *stp_ptr)
  137. {
  138. for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next)
  139.     cout << stp_ptr->name << endl;
  140.     cout << stp_ptr->price << endl;
  141.     cout << stp_ptr->mint_number << endl;
  142.     cout << endl;
  143. }
  144.  
  145. //------------------------------------------------------------------------------
  146. //Find most expensive stamp in list function
  147.  
  148. void
  149. Find_Highest_Stamp(STAMP * &head, STAMP *stp_ptr)
  150. {
  151. long     highest_price = 0;
  152. char  name;
  153.  
  154. for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next) {
  155.     if    (stp_ptr->price > highest_price) {
  156.         highest_price = stp_ptr->price;
  157.         name = stp_ptr->name;
  158.         }
  159.     }
  160. cout    << "THE MOST EXPENSIVE STAMP IN THE LIST IS: " << name    <<    endl;
  161. cout    << "THE COST OF " <<    name <<    "IS "    <<    highest_price    <<    endl;
  162. }
  163. //------------------------------------------------------------------------------
  164. //Find least expensive stamp in list function
  165.  
  166. void
  167. Find_Lowest_Stamp(STAMP * &head, STAMP *stp_ptr)
  168. {
  169. long     lowest_price = 2,147,483,647;
  170. char  name;
  171.  
  172. for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next) {
  173.     if    (stp_ptr->price < lowest_price) {
  174.         lowest_price = stp_ptr->price;
  175.         name = stp_ptr->name;
  176.         }
  177.     }
  178. cout    << "THE LEAST EXPENSIVE STAMP IN THE LIST IS: " << name    <<    endl;
  179. cout    << "THE COST OF " <<    name <<    "IS "    <<    lowest_price    <<    endl;
  180. }
  181. //------------------------------------------------------------------------------
  182. //Delete a choosen record from the list function
  183.  
  184. void
  185. Delete_Stamp_Data(STAMP * &head, STAMP *stp_ptr)
  186. {
  187. int answer;
  188.  
  189. for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next)
  190.     cout << stp_ptr->name << endl;
  191.     cout << stp_ptr->price << endl;
  192.     cout << stp_ptr->mint_number << endl;
  193.     cout << endl;
  194.     cout << "DO YOU WANT TO DELETE THIS RECORD? (Y FOR YES, N FOR NO) " << endl;
  195.     cin  >> answer >> endl;
  196.         if (answer == 'y') {
  197.                      }}
  198.  
  199. //==============================================================================
  200. //Main Program - references above functions to accomplish stamp assignment
  201.  
  202. void
  203. main()
  204. {
  205. STAMP    *head = NULL,
  206.         *stp_ptr;
  207. int    answer;
  208.  
  209. cout     <<    "CHOOSE ONE (1-6) OF THE FOLLOWING MENU OPTIONS:"    <<    endl;
  210. cout  <<    "1    --    ADD A NEW STAMP RECORD"    <<    endl;
  211. cout    <<    "2    --    DISPLAY ALL THE STAMPS IN THE LIST"    <<    endl;
  212. cout    <<    "3    --    DISPLAY THE MOST EXPENSIVE STAMP IN THE LIST"  << endl;
  213. cout  << "4 -- DISPLAY THE LEAST EXPENSIVE STAMP IN THE LIST"  << endl;
  214. cout    <<    "5 -- REMOVE A STAMP FROM THE LIST"    <<    endl;
  215. cout    << "6    --    EXIT THIS PROGRAM"    << endl;
  216.  
  217. cin    >>    answer    >>    endl;
  218.  
  219. switch(answer)
  220. {
  221. case 1:
  222.     stp_ptr = new STAMP;
  223.     stp_ptr->next = NULL;
  224.     Enter_Stamp_Data(stp_ptr);
  225.     Append_Stamp_Node(head, stp_ptr;
  226.     break;
  227. case 2:
  228.  
  229.     break;
  230. case 3:
  231.  
  232.     break;
  233. case 4:
  234.  
  235.     break;
  236. case 5:
  237.  
  238.     break;
  239. case 6:
  240.  
  241.     break;
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248. }
  249.  
  250. --------------18637EF67123--
  251.  
  252.